package com.yyfax.infrastructure.statistics;

import android.app.Activity;
import android.content.Context;
import com.umeng.analytics.MobclickAgent;

import java.util.HashMap;

/**
 * Created by HenryZhang on 2016/10/19.
 */
public class StatService {
	private static final String ATTRIBUTE_KEY_ONE = "key1";
	private static final String ATTRIBUTE_KEY_TWO = "key2";

	public static void onResume(Activity aty) {
		MobclickAgent.onPageStart(aty.getClass().getSimpleName());
		MobclickAgent.onResume(aty);
	}

	public static void onPause(Activity aty) {
		MobclickAgent.onPageEnd(aty.getClass().getSimpleName());
		MobclickAgent.onPause(aty);
	}

	/**
	 * @param eventId 事件ID
	 */
	public static void onEvent(Context ctx, String eventId) {
		MobclickAgent.onEvent(ctx, eventId);
	}

	/**
	 * @param eventId 事件ID
	 */
	public static void onEvent(Context ctx, String eventId, HashMap<String, String> map) {
		MobclickAgent.onEventValue(ctx, eventId, map, 0);
	}

	/**
	 * @param eventId     事件ID
	 * @param attributeId 事件的属性Id
	 */
	public static void onEventFirstKeyAttribute(Context ctx, String eventId, int attributeId) {
		HashMap<String, String> map = new HashMap<>();
		map.put(ATTRIBUTE_KEY_ONE, ctx.getResources().getString(attributeId));
		MobclickAgent.onEventValue(ctx, eventId, map, 0);
	}

	/**
	 * @param eventId   事件ID
	 * @param attribute 事件的属性
	 */
	public static void onEventFirstKeyAttribute(Context ctx, String eventId, String attribute) {
		HashMap<String, String> map = new HashMap<>();
		map.put(ATTRIBUTE_KEY_ONE, attribute);
		MobclickAgent.onEventValue(ctx, eventId, map, 0);
	}

	/**
	 * @param eventId   事件ID
	 * @param attribute 事件的属性
	 */
	public static void onEventSecondKeyAttribute(Context ctx, String eventId, String attribute) {
		HashMap<String, String> map = new HashMap<>();
		map.put(ATTRIBUTE_KEY_TWO, attribute);
		MobclickAgent.onEventValue(ctx, eventId, map, 0);
	}

}
